package com.example.demo.mapper;

import com.example.demo.entity.MusicComment;
import com.example.demo.vo.ViewMusicCommentInfo;
import com.example.demo.vo.ViewNoteCommentInfo;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface MusicCommentMapper {
    @Select("select music_comment_tb.*,u.user_name,c.music_name from music_comment_tb join user_tb u on music_comment_tb.user_id = u.user_id LEFT JOIN music_tb c on music_comment_tb.music_id = c.music_id order by music_comment_tb.music_comment_id")
    List<ViewMusicCommentInfo> findMusicCommentInfo();

    @Select("select music_comment_tb.*,u.user_name,c.music_name from music_comment_tb join user_tb u on music_comment_tb.user_id = u.user_id LEFT JOIN music_tb c on music_comment_tb.music_id = c.music_id  where music_comment_id=#{music_comment_id} order by music_comment_tb.music_comment_id")
    ViewMusicCommentInfo findMusicCommentinfoId(Integer music_comment_id);

    //查找所有评论信息
    @Select("select * from music_comment_tb")
    List<MusicComment> findMusicCommentAll();

    //根据评论id查找评论信息
    @Select("select * from music_comment_tb where music_comment_id=#{music_comment_id}")
    MusicComment findMusicCommentDyId(Integer music_comment_id);

    //添加评论页信息
    @Insert("insert into music_comment_tb (music_id, user_id,content,like_count,create_time,comment_count,status) values(#{music_id},#{user_id},#{content},#{like_count},sysdate(),#{comment_count},#{status})")
    Integer insertMusicComment(MusicComment musicComment);

    //修改评论页信息
    @Update("update music_comment_tb set like_count=#{like_count},comment_count=#{comment_count} where music_comment_id=#{music_comment_id}")
    Integer updateMusicComment(MusicComment musicComment);

    @Delete("delete from music_comment_tb where music_comment_id=#{music_comment_id}")
    Integer deleteMusicComment(Integer music_comment_id);



    //与用户表相关联，且根据笔记id查找,按点赞量排序
    @Select("select music_comment_tb.*,u.user_name,c.music_name from music_comment_tb join user_tb u on music_comment_tb.user_id = u.user_id LEFT JOIN music_tb c on music_comment_tb.music_id = c.music_id where music_comment_tb.music_id=#{music_id} order by music_comment_tb.like_count DESC")
    List<ViewMusicCommentInfo> findMusicCommentInfomusicid(@Param("music_id") Integer music_id);


    //点击举报按钮将会把评论状态从正常修改为被举报
    @Update("update music_comment_tb set status = '被举报' where music_comment_id = #{music_comment_id}")
    Integer updateStatus(Integer music_id);


    //根据笔记ID计数
    @Select("SELECT COUNT(*) FROM music_comment_tb WHERE music_id= #{music_id}")
    Integer countcomment(@Param("music_id") Integer music_id);
}
